setCookie('newsUserId','18');
setCookie('newsAccount','15727527694');
var userId = getCookie('newsUserId');
var website = 'http://news.whilte.com';


console.log('userId------',userId);
if(userId=='undefined' || userId==null || userId==''){
    console.log('你没有userid，进了')
    var param = "code";
    var reg = new RegExp("(^|&)" + param + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg); //匹配目标参数

    var param1 = "code1";
    var reg1 = new RegExp("(^|&)" + param1 + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r1 = window.location.search.substr(1).match(reg1); //匹配目标参数
    if(r1!=null){
        var code1 = r1[2];
        setCookie('invitationCode',code1);
    }

    if(r==null){
        window.location.href='https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxed752d87990909bb&redirect_uri=http://newst.whilte.com/index.html&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect';
    }
    if (r != null) {
        var code = r[2];
        var invitationCode =  getCookie('invitationCode');

        $.ajax({
            url: website+"/Share1/oauth",
            type: "post",
            data: {
                code: code,
                invitationCode: invitationCode
            },
            success: function (data) {
                setCookie('newsUserId',data.userId);
                console.log(data);
                userId = data.userId;
            }
        });

    }
}else{

    var account = getCookie('newsAccount');
    console.log('account------',account);
    if(account=='undefined' || account==null || account==''){

        $.ajax({
            url: website + "/UserController/queryUserInformation",
            type: "post",
            data: {
                "userId": userId,
            },
            success: function (data) {
                if(data.data.account==null || data.data.account==''){
                    window.location.href='../../html/account.html';
                }else{
                    setCookie('newsAccount',data.data.account);
                }
            },
        })
    }

}